import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:travel/model/homepage.dart';
import 'package:travel/model/hotel.dart';
import 'package:travel/model/theme.dart';
import 'package:travel/model/tourism.dart';
import 'package:travel/routes/index.dart';
import 'package:travel/screen/flutter_screenutil.dart';
import 'package:travel/ui/scroll_refresh_config.dart';
import 'package:travel/utils/colors.dart';
import 'package:travel/utils/styles.dart';
import 'package:travel/utils/tools.dart';

/// 景点
class CollectAttractions extends StatefulWidget {
  const CollectAttractions({super.key});

  @override
  State<CollectAttractions> createState() => _CollectAttractionsState();
}

class _CollectAttractionsState extends State<CollectAttractions> {
  List<ThemeTourismModel> pageList = [];

  RefreshController refreshController = RefreshController();

  @override
  void initState() {
    initData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return scrollRefreshConfig(context);
  }

  @override
  void dispose() {
    refreshController.dispose();
    super.dispose();
  }

  void initData() {
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '故宫博物馆',
        level: 5,
        point: 4.6,
        evaluate: 5487,
        distance: 1.2,
        price: 40,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '八达岭长城',
        level: 5,
        point: 4.5,
        evaluate: 5687,
        distance: 1.5,
        price: 35,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '香山公园',
        level: 3,
        point: 4.3,
        evaluate: 3487,
        distance: 1.8,
        price: 20,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '白塔寺',
        level: 5,
        point: 4.6,
        evaluate: 5487,
        distance: 1.2,
        price: -1,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '湖广会馆',
        level: 5,
        point: 4.6,
        evaluate: 5487,
        distance: 1.2,
        price: -1,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '北京古代建筑博物管',
        level: 5,
        point: 4.6,
        evaluate: 5487,
        distance: 1.2,
        price: 0,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '北京杜莎夫人蜡像馆',
        level: 5,
        point: 4.6,
        evaluate: 5487,
        distance: 1.2,
        price: 90,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '中国国家博物管',
        level: 5,
        point: 4.6,
        evaluate: 5487,
        distance: 1.2,
        price: -1,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '天安门广场',
        level: 5,
        point: 4.6,
        evaluate: 5487,
        distance: 1.2,
        price: 0,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
    pageList.add(ThemeTourismModel(
        imgUrl:
            'https://img2.baidu.com/it/u=614279430,1420774946&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        name: '史家胡同博物馆',
        level: 5,
        point: 4.6,
        evaluate: 5487,
        distance: 1.2,
        price: 0,
        tags: ['可订明日', '随时退'],
        address: '北海市海城区景山前街4号'));
  }

  Future<void> onRefresh() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));
    refreshController.refreshCompleted(resetFooterState: true);
  }

  Future<void> onLoading() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));

    /// if failed, use loadFailed(), if no data return, use LoadNodata()
    if (pageList.length > 32) {
      return refreshController.loadNoData();
    }

    /// 添加数据
    setState(initData);

    /// 完毕
    refreshController.loadComplete();
  }

  Widget scrollRefreshConfig(BuildContext context) {
    return ScrollRefreshConfig(
      refreshController: refreshController,
      onRefresh: onRefresh,
      onLoading: onLoading,
      child: listViewBuilder(context),
    );
  }

  ListView listViewBuilder(BuildContext context) {
    return ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        var row = pageList[index];
        return InkWell(
          onTap: () {
            Get.toNamed(RoutePath.attractions, arguments: {'model': row});
          },
          child: Container(
            margin: EdgeInsets.only(top: 10.h),
            padding: EdgeInsets.symmetric(horizontal: 15.w),
            decoration: const BoxDecoration(color: Colors.white),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: 120.w,
                  height: 120.w,
                  alignment: Alignment.topLeft,
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(8.w),
                    child: CachedNetworkImage(
                      imageUrl: row.imgUrl,
                      alignment: Alignment.topLeft,
                      fit: BoxFit.cover,
                      width: 120.w,
                      height: 120.w,
                      placeholder: (context, url) => const CircularProgressIndicator(),
                    ),
                  ),
                ),
                Expanded(
                    child: Container(
                  padding: EdgeInsets.only(left: 10.w),
                  child: Column(
                    children: [
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          row.name,
                          style: StylesUtils.customTextStyle(
                              fontSize: 16.sp,
                              fontWeight: FontWeight.w700,
                              color: ColorsUtils.color3333),
                        ),
                      ),
                      Container(
                          alignment: Alignment.centerLeft,
                          margin: EdgeInsets.symmetric(vertical: 10.w),
                          child: Container(
                            constraints: BoxConstraints.tightFor(width: 24.w, height: 18.h),
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                                color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2),
                                borderRadius: BorderRadius.circular(3.w)),
                            child: Text(
                              '${row.level}A',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color6666, fontSize: 12.sp),
                            ),
                          )),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Wrap(
                          spacing: 10.w,
                          crossAxisAlignment: WrapCrossAlignment.center,
                          children: [
                            Text(
                              '${row.point}分',
                              style: StylesUtils.customTextStyle(
                                  fontSize: 12.sp, color: ColorsUtils.color7979),
                            ),
                            Text(
                              '${row.evaluate}人评价',
                              style: StylesUtils.customTextStyle(
                                  fontSize: 12.sp, color: ColorsUtils.color7979),
                            )
                          ],
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        margin: EdgeInsets.symmetric(vertical: 10.w),
                        child: Text(
                          '${row.address}',
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: StylesUtils.customTextStyle(
                              fontSize: 12.sp, color: ColorsUtils.color7979),
                        ),
                      ),
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            getChildPrice(row.price),
                            ToolsUtils.assetImageSvg('u2109.svg', width: 15.w, height: 4.h)
                          ],
                        ),
                      )
                    ],
                  ),
                ))
              ],
            ),
          ),
        );
      },
      itemCount: pageList.length,
      itemExtent: 146.h,
    );
  }

  Text getChildPrice(int price) {
    if (price < 0) {
      return Text(
        '免费预约',
        style: StylesUtils.customTextStyle(
          color: ColorsUtils.color6666,
        ),
      );
    }
    if (price == 0) {
      return Text(
        '免费',
        style: StylesUtils.customTextStyle(color: ColorsUtils.color6666),
      );
    }
    return Text.rich(TextSpan(children: [
      TextSpan(
          text: '￥',
          style: StylesUtils.customTextStyle(fontSize: 12.sp, color: ColorsUtils.colorD900)),
      TextSpan(
          text: '$price',
          style: StylesUtils.customTextStyle(
              fontSize: 20.sp, fontWeight: FontWeight.w700, color: ColorsUtils.colorD900)),
      TextSpan(
          text: '起',
          style: StylesUtils.customTextStyle(fontSize: 12.sp, color: ColorsUtils.color7979))
    ]));
  }
}

/// 文章
class CollectArticle extends StatefulWidget {
  const CollectArticle({super.key});

  @override
  State<CollectArticle> createState() => _CollectArticleState();
}

class _CollectArticleState extends State<CollectArticle> {
  RefreshController refreshController = RefreshController();

  List<TourismModel> pageList = [];

  @override
  void initState() {
    initData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return scrollRefreshConfig(context);
  }

  @override
  void dispose() {
    refreshController.dispose();
    super.dispose();
  }

  void initData() {
    pageList.add(TourismModel(
        imgUrl: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p0.png',
        describe: '和家人果断在北京续住3天的神仙小院',
        avatar: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p1.png',
        browse: 1.1,
        nickname: '晚风心里吹'));
    pageList.add(TourismModel(
        imgUrl: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p7.png',
        describe: '人少景美“京西小故宫”修缮五年后惊艳开放',
        avatar: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p8.png',
        browse: 1.3,
        nickname: '唐糖唐来了'));
    pageList.add(TourismModel(
        imgUrl: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p2.png',
        describe: '北京海拔2000米的木栈道帝都最高观景平台',
        avatar: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p3.png',
        browse: 2.1,
        nickname: '美腻的猫'));
    pageList.add(TourismModel(
        imgUrl: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p9.png',
        describe: '和家人果断在北京续住3天的神仙小院',
        avatar: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p10.png',
        browse: 1.1,
        nickname: '小沈阳10'));

    pageList.add(TourismModel(
        imgUrl: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p4.png',
        describe: '北京郊区大自然山景私汤山酒店',
        avatar: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p5.png',
        browse: 1.1,
        nickname: '美美在旅行'));
    pageList.add(TourismModel(
        imgUrl: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p11.png',
        describe: '人少景美“京西小故宫”修缮五年后惊艳开放',
        avatar: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p12.png',
        browse: 1.7,
        nickname: '美美在旅行'));
    pageList.add(TourismModel(
        imgUrl: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p6.png',
        describe: '北京周末去哪，找到了人少景美的仙境了！',
        avatar: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p1.png',
        browse: 3.1,
        nickname: '晚风吹心里'));
    pageList.add(TourismModel(
        imgUrl: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p13.png',
        describe: '秋冬京城小奈良动物园里泡温泉',
        avatar: 'https://cdn7.axureshop.com/demo2023/2251242/images/首页_未登录/p10.png',
        browse: 1.1,
        nickname: '万能夏小姐'));
  }

  Future<void> onRefresh() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));
    refreshController.refreshCompleted(resetFooterState: true);
  }

  Future<void> onLoading() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));

    /// if failed, use loadFailed(), if no data return, use LoadNodata()
    if (pageList.length > 32) {
      return refreshController.loadNoData();
    }

    /// 添加数据
    setState(initData);

    /// 完毕
    refreshController.loadComplete();
  }

  Widget scrollRefreshConfig(BuildContext context) {
    return ScrollRefreshConfig(
      refreshController: refreshController,
      onRefresh: onRefresh,
      onLoading: onLoading,
      child: scrollViewBuilder(context),
    );
  }

  SingleChildScrollView scrollViewBuilder(BuildContext context) {
    return SingleChildScrollView(
      padding: EdgeInsets.symmetric(horizontal: 15.w),
      child: StaggeredGrid.count(
        crossAxisCount: 2,
        crossAxisSpacing: 10,
        children: pageList
            .map((e) => Container(
                  margin: EdgeInsets.only(top: 10.h),
                  child: Column(
                    children: [
                      Container(
                        height: 175.h,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                topLeft: Radius.circular(8.w), topRight: Radius.circular(8.w)),
                            image: DecorationImage(
                                alignment: Alignment.topLeft,
                                fit: BoxFit.fill,
                                filterQuality: FilterQuality.high,
                                image: NetworkImage(
                                  e.imgUrl,
                                ))),
                      ),
                      Container(
                        margin: EdgeInsets.symmetric(vertical: 8.w),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          e.describe,
                          overflow: TextOverflow.ellipsis,
                          maxLines: 2,
                          style: StylesUtils.customTextStyle(
                              fontWeight: FontWeight.w700,
                              color: ColorsUtils.color3333,
                              lineHeight: 1.5),
                        ),
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Expanded(
                              child: Text.rich(
                            TextSpan(children: [
                              WidgetSpan(
                                  child: CircleAvatar(
                                radius: 10,
                                backgroundImage: NetworkImage(e.avatar),
                              )),
                              TextSpan(
                                  text: '  ${e.nickname}',
                                  style: StylesUtils.customTextStyle(
                                      color: ColorsUtils.color6666, fontSize: 13.sp))
                            ]),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          )),
                          ToolsUtils.assetImageSvg('u2109.svg', width: 15.w, height: 4.h)
                        ],
                      )
                    ],
                  ),
                ))
            .toList(),
      ),
    );
  }
}

/// 视频
class CollectVideo extends StatefulWidget {
  const CollectVideo({super.key});

  @override
  State<CollectVideo> createState() => _CollectVideoState();
}

class _CollectVideoState extends State<CollectVideo> {
  RefreshController refreshController = RefreshController();

  List<HomepageVideoModel> pageList = [];

  @override
  void initState() {
    initData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return scrollRefreshConfig(context);
  }

  @override
  void dispose() {
    refreshController.dispose();
    super.dispose();
  }

  void initData() {
    pageList.add(HomepageVideoModel(
        imgUrl:
            'https://img1.baidu.com/it/u=3237643364,3711617777&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500',
        previewCount: 10,
        describe: '和家人果断在北京续住3天的神仙小院',
        avatar:
            'https://img2.baidu.com/it/u=758153736,4149288328&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
        nickname: '晚风心里吹'));
    pageList.add(HomepageVideoModel(
        imgUrl:
            'https://img0.baidu.com/it/u=1532705034,533831030&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        previewCount: 10,
        describe: '和家人果断在北京续住3天的神仙小院',
        avatar:
            'https://img2.baidu.com/it/u=758153736,4149288328&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
        nickname: '晚风心里吹'));
    pageList.add(HomepageVideoModel(
        imgUrl:
            'https://img0.baidu.com/it/u=1532705034,533831030&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        previewCount: 10,
        describe: '和家人果断在北京续住3天的神仙小院',
        avatar:
            'https://img2.baidu.com/it/u=758153736,4149288328&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
        nickname: '晚风心里吹'));
    pageList.add(HomepageVideoModel(
        imgUrl:
            'https://img0.baidu.com/it/u=1532705034,533831030&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        previewCount: 10,
        describe: '和家人果断在北京续住3天的神仙小院',
        avatar:
            'https://img2.baidu.com/it/u=758153736,4149288328&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
        nickname: '晚风心里吹'));
    pageList.add(HomepageVideoModel(
        imgUrl:
            'https://img0.baidu.com/it/u=1532705034,533831030&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        previewCount: 10,
        describe: '和家人果断在北京续住3天的神仙小院',
        avatar:
            'https://img2.baidu.com/it/u=758153736,4149288328&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
        nickname: '晚风心里吹'));
    pageList.add(HomepageVideoModel(
        imgUrl:
            'https://img0.baidu.com/it/u=1532705034,533831030&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500',
        previewCount: 10,
        describe: '和家人果断在北京续住3天的神仙小院',
        avatar:
            'https://img2.baidu.com/it/u=758153736,4149288328&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
        nickname: '晚风心里吹'));
  }

  Widget scrollRefreshConfig(BuildContext context) {
    return ScrollRefreshConfig(
      refreshController: refreshController,
      onRefresh: onRefresh,
      onLoading: onLoading,
      child: scrollViewBuilder(context),
    );
  }

  Future<void> onRefresh() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));
    refreshController.refreshCompleted(resetFooterState: true);
  }

  Future<void> onLoading() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));

    /// if failed, use loadFailed(), if no data return, use LoadNodata()
    if (pageList.length > 32) {
      return refreshController.loadNoData();
    }

    /// 添加数据
    setState(initData);

    /// 完毕
    refreshController.loadComplete();
  }

  SingleChildScrollView scrollViewBuilder(BuildContext context) {
    return SingleChildScrollView(
      padding: EdgeInsets.symmetric(horizontal: 15.w),
      child: StaggeredGrid.count(
        crossAxisCount: 2,
        crossAxisSpacing: 5.w,
        children: pageList.map((row) {
          double width = ToolsUtils.calculateTextHeight(
              context, ' ${row.previewCount}', FontWeight.normal, 12.sp, 150.w, 1);
          return InkWell(
            onTap: () {
              Get.toNamed(RoutePath.videoInfo);
            },
            child: Container(
              margin: EdgeInsets.only(top: 10.h),
              decoration: const BoxDecoration(color: Colors.white),
              child: Column(
                children: [
                  Container(
                    width: 172.w,
                    height: 215.h,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(8.w), topRight: Radius.circular(8.w)),
                        image: DecorationImage(
                            image: NetworkImage(row.imgUrl),
                            fit: BoxFit.cover,
                            alignment: Alignment.topLeft)),
                    child: Stack(
                      fit: StackFit.expand,
                      children: [
                        Positioned(
                            top: 5,
                            right: 10,
                            child: Container(
                              width: 28.w,
                              height: 28.w,
                              alignment: Alignment.center,
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(14.w),
                                  color: ColorsUtils.rgba(0, 0, 0, 0.698039)),
                              child: ToolsUtils.assetImageSvg('u207.svg'),
                            )),
                        Positioned(
                            left: 5.w,
                            bottom: 5.w,
                            child: Container(
                              constraints: BoxConstraints(minHeight: 18.h, maxWidth: width + 25.w),
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(9.h),
                                  color: ColorsUtils.rgba(0, 0, 0, 0.698039215686274)),
                              alignment: Alignment.center,
                              child: Text.rich(TextSpan(children: [
                                WidgetSpan(
                                    child: ToolsUtils.assetImageSvg('u2896.svg',
                                        width: 14.w, height: 9.h),
                                    alignment: PlaceholderAlignment.middle),
                                TextSpan(
                                    text: ' ${row.previewCount}',
                                    style: StylesUtils.customTextStyle(
                                        color: ColorsUtils.colorF2f2, fontSize: 12.sp))
                              ])),
                            ))
                      ],
                    ),
                  ),
                  Container(
                    padding: EdgeInsets.symmetric(vertical: 10.h, horizontal: 5.h),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.only(
                            bottomLeft: Radius.circular(8.w), bottomRight: Radius.circular(8.w))),
                    child: Column(
                      children: [
                        Container(
                          alignment: Alignment.centerLeft,
                          child: Text(
                            row.describe,
                            style: StylesUtils.customTextStyle(
                                fontSize: 13.sp,
                                fontWeight: FontWeight.w700,
                                color: ColorsUtils.color3333,
                                lineHeight: 1.5.h),
                            maxLines: 2,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top: 10.h),
                          alignment: Alignment.centerLeft,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text.rich(TextSpan(children: [
                                WidgetSpan(
                                    child: CircleAvatar(
                                      radius: 10.w,
                                      backgroundImage: NetworkImage(row.avatar),
                                    ),
                                    alignment: PlaceholderAlignment.middle),
                                TextSpan(
                                    text: ' ${row.nickname}',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: 12.sp, color: ColorsUtils.color9999))
                              ])),
                              ToolsUtils.assetImageSvg('u2156.svg', width: 15.w, height: 4.h)
                            ],
                          ),
                        )
                      ],
                    ),
                  )
                ],
              ),
            ),
          );
        }).toList(),
      ),
    );
  }
}

/// 酒店
class CollectHotel extends StatefulWidget {
  const CollectHotel({super.key});

  @override
  State<CollectHotel> createState() => _CollectHotelState();
}

class _CollectHotelState extends State<CollectHotel> {
  RefreshController refreshController = RefreshController();

  List<HotelModel> pageList = [];

  @override
  void initState() {
    initData();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return scrollRefreshConfig(context);
  }

  @override
  void dispose() {
    refreshController.dispose();
    super.dispose();
  }

  void initData() {
    pageList.add(HotelModel(
        name: '锦江之星风尚酒店(北海三里屯店)',
        address: '北海市海城区东直门外南二里庄29号1幢',
        price: 579,
        area: '海城区',
        imgUrl:
            'https://ns-strategy.cdn.bcebos.com/ns-strategy/upload/fc_big_pic/part-00002-713.jpg'));
    pageList.add(HotelModel(
        name: '北海万达文华酒店',
        address: '北海市银海区东直门外南二里庄29号1幢',
        price: 399,
        area: '银海区',
        imgUrl:
            'https://img1.baidu.com/it/u=2046807301,2551492904&fm=253&fmt=auto&app=138&f=JPEG?w=888&h=500'));
    pageList.add(HotelModel(
        name: '北海广渠门漫心酒店',
        address: '北海市合浦县东直门外南二里庄29号1幢',
        price: 478,
        area: '合浦县',
        imgUrl:
            'https://img1.baidu.com/it/u=1512264951,2503995626&fm=253&fmt=auto&app=120&f=JPEG?w=1200&h=800'));
    pageList.add(HotelModel(
        name: '锦江之星风尚酒店(北海三里屯店)',
        address: '北海市海城区东直门外南二里庄29号1幢',
        price: 389,
        area: '海城区',
        imgUrl:
            'https://img2.baidu.com/it/u=3206337597,3928032791&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500'));
    pageList.add(HotelModel(
        name: '北海望京希尔顿欢朋酒店',
        address: '北海市海城区东直门外南二里庄29号1幢',
        price: 189,
        area: '海城区',
        imgUrl:
            'https://img2.baidu.com/it/u=874687570,4272745671&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500'));
    pageList.add(HotelModel(
        name: '全季酒店(北海天坛店)',
        address: '北海市海城区东直门外南二里庄29号1幢',
        price: 489,
        area: '海城区',
        imgUrl:
            'https://img2.baidu.com/it/u=1915459,4007195949&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500'));
    pageList.add(HotelModel(
        name: '北海望京希尔顿欢朋酒店',
        address: '北海市铁山港区东直门外南二里庄29号1幢',
        price: 289,
        area: '铁山港区',
        imgUrl:
            'https://img2.baidu.com/it/u=1915459,4007195949&fm=253&fmt=auto&app=138&f=JPEG?w=750&h=500'));
  }

  Future<void> onRefresh() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));
    refreshController.refreshCompleted(resetFooterState: true);
  }

  Future<void> onLoading() async {
    /// 发起请求
    await Future.delayed(const Duration(milliseconds: 2000));

    /// if failed, use loadFailed(), if no data return, use LoadNodata()
    if (pageList.length > 35) {
      return refreshController.loadNoData();
    }

    /// 添加数据
    setState(initData);

    /// 完毕
    refreshController.loadComplete();
  }

  ScrollRefreshConfig scrollRefreshConfig(BuildContext context) {
    return ScrollRefreshConfig(
      refreshController: refreshController,
      onRefresh: onRefresh,
      onLoading: onLoading,
      child: listViewBuilder(context),
    );
  }

  ListView listViewBuilder(BuildContext context) {
    return ListView.builder(
      padding: EdgeInsets.symmetric(horizontal: 15.w),
      itemBuilder: (_, index) {
        var row = pageList[index];
        return InkWell(
          onTap: () {
            Get.toNamed(RoutePath.hotelInfo, arguments: {'hotel': row});
          },
          child: Container(
            margin: EdgeInsets.only(top: 10.h),
            padding: EdgeInsets.symmetric(vertical: 7.5.h, horizontal: 10.w),
            decoration:
                BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
            child: Row(
              children: [
                Stack(
                  children: [
                    ClipRRect(
                      borderRadius: BorderRadius.circular(5.w),
                      child: CachedNetworkImage(
                        imageUrl: row.imgUrl,
                        width: 90.w,
                        height: 90.h,
                        fit: BoxFit.fill,
                      ),
                    ),
                    Positioned(
                        left: 0,
                        bottom: 0,
                        right: 0,
                        child: Container(
                          height: 20.h,
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                              color: ColorsUtils.rgba(0, 0, 0, 0.6),
                              borderRadius: BorderRadius.only(
                                  bottomLeft: Radius.circular(5.w),
                                  bottomRight: Radius.circular(5.w))),
                          child: Text(
                            row.area,
                            style: StylesUtils.customTextStyle(
                              fontSize: 12.sp,
                            ),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ))
                  ],
                ),
                Expanded(
                    child: Container(
                  padding: EdgeInsets.only(left: 10.w),
                  child: Column(
                    children: [
                      Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          row.name,
                          style: StylesUtils.customTextStyle(
                              fontSize: 15.sp,
                              fontWeight: FontWeight.w700,
                              color: ColorsUtils.color3333),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      Expanded(
                          child: Container(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          row.address,
                          style: StylesUtils.customTextStyle(
                              fontSize: 12.sp, color: ColorsUtils.color9999),
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                        ),
                      )),
                      Container(
                          alignment: Alignment.centerLeft,
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text.rich(TextSpan(children: [
                                TextSpan(
                                    text: '￥',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: 13.sp, color: ColorsUtils.colorD900)),
                                TextSpan(
                                    text: ' ${row.price} ',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: 20.sp,
                                        fontWeight: FontWeight.w700,
                                        color: ColorsUtils.colorD900)),
                                TextSpan(
                                    text: '起',
                                    style: StylesUtils.customTextStyle(
                                        fontSize: 12.sp, color: ColorsUtils.color9999))
                              ])),
                              ToolsUtils.assetImageSvg('u2156.svg', width: 15.w, height: 4.h)
                            ],
                          ))
                    ],
                  ),
                ))
              ],
            ),
          ),
        );
      },
      itemCount: pageList.length,
      itemExtent: 130.h,
      cacheExtent: 130.h,
    );
  }
}
